<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class c_laporan extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->model("m_laporan");
		$this->load->model("m_setup");
		$this->load->model("m_entry");
	}
	
	function index(){
		$data["data_print"] = $this->m_laporan->laporan_detailjadwal();
		$html = $this->load->view("laporan/l_detailjadwal",$data,true);
		
		$file = fopen("report/print/laporandetailjadwal.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data["data_print"] = $this->m_laporan->laporan_rekapjadwal();
		$html = $this->load->view("laporan/l_rekapjadwal",$data,true);
		
		$file = fopen("report/print/laporanrekapjadwal.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data["data_print"] = $this->m_laporan->laporan_pic();
		$html = $this->load->view("laporan/l_pic",$data,true);
		
		$file = fopen("report/print/pic.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$this->load->view('v_laporan',null);
	}

	function detail($js = false){
		$data["data_print"] = $this->m_laporan->laporan_detailjadwal();
		$html = $this->load->view("laporan/l_detailjadwal",$data,true);
		
		$file = fopen("report/print/detail.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		
		$file = fopen("report/print/detail.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "detail";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function pq($js = false){
		$data["data_print"] = $this->m_laporan->laporan_pq();
		$html = $this->load->view("laporan/l_pq",$data,true);
		
		$file = fopen("report/print/pq.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		
		$file = fopen("report/print/pq.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "pq";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function rekap($js = false){
		$data["batas_merah"] = $this->m_setup->get_param("MERAH");
		$data["batas_kuning"] = $this->m_setup->get_param("KUNING");
		$data["batas_hijau"] = $this->m_setup->get_param("HIJAU");
		$data["data_print"] = $this->m_laporan->laporan_rekapjadwal();
		$html = $this->load->view("laporan/l_rekapjadwal",$data,true);
		
		$file = fopen("report/print/rekap.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$file = fopen("report/print/rekap.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "rekap";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function pic($js = false){
		$data["data_print"] = $this->m_laporan->laporan_pic();
		$html = $this->load->view("laporan/l_pic",$data,true);
		
		$file = fopen("report/print/pic.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$file = fopen("report/print/pic.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "pic";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function hasil($js = false){
		$data_where["cabang"] = $this->input->post("cmb-cabang");
		$data_where["tahun"] = $this->input->post("cmb-tahun");
		$data["tahun"] = $data_where["tahun"];
		$data["data_print"] = $this->m_laporan->laporan_hasil($data_where);
		$html = $this->load->view("laporan/l_hasil",$data,true);
		
		$file = fopen("report/print/hasil.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$file = fopen("report/print/hasil.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "hasil";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function masterlist($js = false){
		$data_where["cabang"] = $this->input->post("cmb-cabang");
		$data_where["tahun"] = $this->input->post("cmb-tahun");
		$data["tahun"] = $data_where["tahun"];
		$data["data_print"] = $this->m_laporan->laporan_masterlist($data_where);
		$html = $this->load->view("laporan/l_masterlist",$data,true);
		
		$file = fopen("report/print/masterlist.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$file = fopen("report/print/masterlist.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "masterlist";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
	
	function printform($file,$js = false){
		$data["file"] = $file ;
		$data["js"] = $js ;
		$data['data_cabang'] = $this->m_entry->getCabang("combo");
		$data['data_tahun'] = $this->m_laporan->getTahun($file);
		$this->load->view("v_formlaporan",$data);
	}
    
    function tenderpekan($js = false){
		$data_where["cabang"] = $this->input->post("cmb-cabang");
		$data_where["tahun"] = $this->input->post("cmb-tahun");
		$data_where["pekanawal"] = $this->input->post("cmb-pekanawal");
		$data_where["pekanakhir"] = $this->input->post("cmb-pekanakhir");
		$data["pekanawal"] = $this->input->post("cmb-pekanawal");
		$data["pekanakhir"] = $this->input->post("cmb-pekanakhir");
		$data["tahun"] = $data_where["tahun"];
		$data["data_print"] = $this->m_laporan->laporan_tenderpekan($data_where);
		$data["data_print2"] = $this->m_laporan->laporan_tenderpekan2($data_where);
		$html = $this->load->view("laporan/l_tenderpekan",$data,true);
		
		$file = fopen("report/print/tenderpekan.html","w+");
		fwrite($file,$html);
		fclose($file);
		
		$file = fopen("report/print/tenderpekan.xls","w+");
		fwrite($file,$html);
		fclose($file);
		
		$data_view["content"] = $html;
		$data_view["bagian"] = "tenderpekan";
		$data_view["js"] = $js;
		$this->load->view('v_laporan',$data_view);
	}
}